package ws.very.common.web.views

import ws.very.util.lang.FileSize

object FileInfos {
  import FileSize._
  def fileSize(filesize: Long): String =
    (if (filesize >= GB.u)
      "GB" -> GB.u
    else if (filesize >= MB.u)
      "MB" -> MB.u
    else if (filesize >= KB.u)
      "KB" -> KB.u
    else
      "Bytes" -> Byte.u) match {
      case (strUnit, 1) => filesize + " " + strUnit
      case (strUnit, intDivisor) =>
        //val strAfterComma = "" + 100 * (filesize % intDivisor) / intDivisor ??= ".0"
        filesize / intDivisor + "." + 100 * (filesize % intDivisor) / intDivisor + " " + strUnit
    }
}